package roborally.model.executables.commands;

import roborally.model.*;
import roborally.model.executables.RobotCommand;
/**
 * RobotCommand that lets the robot pick up on item on its current position if it is possible, and lets the robot use the item.
 */
public class PickupAndUse extends RobotCommand {

	public PickupAndUse(Robot robot, Program program) {
		super(robot, program);
	}
	/**
	 * @effect If the field the robot is positioned on has at least one item on it, the robot will pick up a random item on this field and use it.
	 */
	@Override
	public void executeCommand() {
		if(!getRobot().isPlacedOnBoard()) return;
		if(getRobot().getField().hasItem()){//The field contains at least one item
			Item item = getRobot().getField().getRandomItem();
			getRobot().pickUpItem(item);
			getRobot().useItem(item);
		}
	}
	
	@Override
	public String toString(){
		return "pickup-and-use";
	}

}
